home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / neue_programme / biz / datenbank / afile / example / disksstats.rexx < prev   
OS/2 REXX Batch file  |  1995-06-01  |  1KB  |  72 lines

  1. /*
  2.  * This is a sample script which is called with the "Stats" item,
  3.  * installed using the $MENU specification in the input mask
  4.  *
  5.  * It shows how to control AFile using AREXX
  6.  *
  7.  * This script counts how many disks have been purchased each year
  8.  */
  9.  
  10. SIGNAL ON ERROR
  11. OPTIONS RESULTS
  12. ADDRESS "AFile_rexx"
  13.  
  14. /* reset variables */
  15. Year  = 0
  16. Count = 0
  17. SAY "Number of disks purchased by year" || D2C(10)
  18.  
  19. /* sort the file on purchase date (ascending order) */
  20. "SORT PURCHASE"
  21.  
  22. /* process all the records */
  23. "SEEK FIRST"
  24. DO FOREVER
  25.  
  26.     /* get year of purchase in current record */
  27.     "GETFIELD PURCHASE"
  28.     NewYear = RIGHT( RESULT , 2 )
  29.  
  30.     /* compare with previous year */
  31.     IF NewYear ~= Year THEN DO
  32.     CALL DisplayResult( Year Count )
  33.     Count = 0
  34.     END
  35.  
  36.     /* update count */
  37.     Year  = NewYear
  38.     Count = Count + 1
  39.  
  40.     /* read next record */
  41.     "SEEK NEXT"
  42. END
  43.  
  44. /*
  45.  * We should come here only because "SEEK NEXT" has returned an error
  46.  * (end of file)
  47.  */
  48.  
  49. ERROR:
  50.  
  51. /* flush last result */
  52. CALL DisplayResult( Year Count )
  53.  
  54. /* release sort */
  55. "RELEASE ALL"
  56.  
  57. EXIT 0
  58.  
  59. /*
  60.  * Procedure called to display the result for one year
  61.  */
  62.  
  63. DisplayResult: PROCEDURE
  64.     PARSE ARG Year Count
  65.  
  66.     IF Year ~= 0 THEN DO
  67.         SAY "19" || Year || " : " || Count
  68.     END
  69.  
  70.     RETURN "0"
  71.  
  72.